/**
 *    @file       cfile.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       12/10/2012 07:38:21 PM
 *
 *    @author     Theophilus, wangtf418@gmail.com
 */
#ifndef _BF_CFILE_H_
#define _BF_CFILE_H_
#include <sys/stat.h>
#include <stdio.h>
#include <string>
#include "comdef.h"

class cfile
{
public:
	cfile();
	cfile(const std::string &filename);
	virtual ~cfile();

public:
	void set_filename(const std::string &filename);
	std::string & get_filename();
	FILE * get_file();
	struct stat * stat();
	struct stat * get_filestat();
	bf_int_t set_filetime(bf_time_t modify_time, bf_time_t access_time);

public:
	bf_int_t open(const std::string &mode);	
	bf_int_t close();

	bf_int_t seek(bf_long_t seek_offset, bf_int_t whence = SEEK_SET);
	bf_int_t read(void *read_buf, bf_size_t read_len);
	bf_int_t write(const void *write_buf, bf_size_t write_len);
	bf_int_t print(const bf_char_t *format, ...);
	bf_int_t vprint(const bf_char_t *format, bf_valist_t &ap);
	bf_int_t flush();

public:
	bf_int_t remove();
	bf_int_t move(const std::string &dst_filename, bf_bool_t ifoverwrite = false);
	bf_int_t copy(const std::string &dst_filename, bf_bool_t ifoverwrite = false);
	bf_int_t is_exist();
	bf_int_t is_dir();
	bf_int_t is_file();
	bf_int_t is_link();

public:
	inline bf_int_t get_errno() {return m_errno;}

protected:
	std::string m_filename;
	std::string m_mode;
	FILE *m_file;
	struct stat *m_filestat;
	bf_int_t m_errno;
};

#endif

